
	import { Vue, Component } from 'vue-property-decorator'
	import PageContainer from '@/moduleC/components/layout/PageContainer.vue'
	import { api } from '@/moduleC/api'
	import store from '@/moduleC/store'
	interface UserInfo {
		avatar : string
		name : string
	}
	
	interface ImageList {
		save : string
		share : string
		shareimg : string
	}
	
	interface ShareOptions {
		title : string
		path : string
		imageUrl : string
		success ?: (res : any) => void
		fail ?: (err : any) => void
	}
	
	const _imgList : ImageList = {
		save: '',
		share: '',
		shareimg: 'http://sq85owu9k.hb-bkt.clouddn.com/lingpin/static/lottery/qrcode.png'
	}
	@Component({
		components: {
			PageContainer
		}
	})
	export default class OrderDetails extends Vue {
		inviteCode : string = '20250109'
		qrCodeUrl : string = 'http://sq85owu9k.hb-bkt.clouddn.com/lingpin/static/lottery/qrcode.png'
		statusBarHeight : number = 0
		navHeight : number = 110
		errors : string = ''
		userInfo : UserInfo = uni.getStorageSync('_UserInfo') || { avatar: '', name: '' }
		imgList : ImageList = _imgList
		
		onLoad() : void {
			const systemInfo = uni.getSystemInfoSync()
			if (systemInfo.statusBarHeight !== undefined) {
				this.statusBarHeight = systemInfo.statusBarHeight
			}
		}
		
		goBack() : void {
			uni.navigateBack()
		}
		
		copyInviteCode() : void {
			uni.setClipboardData({
				data: this.inviteCode,
				success: () => {
					uni.showToast({
						title: '邀请码已复制',
						icon: 'success'
					})
				}
			})
		}
		
		saveImage() : void {
			uni.authorize({
				scope: 'scope.writePhotosAlbum',
				success: () => {
					uni.downloadFile({
						url: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDbkrjHBvuTXJIk37IGWQHNR36qH49-qWKvQ&s',
						success: (res : UniNamespace.DownloadSuccessData) => {
							if (res.statusCode === 200) {
								uni.saveImageToPhotosAlbum({
									filePath: res.tempFilePath,
									success: () => {
										uni.showToast({
											title: '保存成功',
											icon: 'success'
										})
									},
									fail: (err : any) => {
										uni.showToast({
											title: '保存失败',
											icon: 'none'
										})
										console.error('Save failed:', err)
									}
								})
							}
						},
						fail: (err : any) => {
							console.error('Download failed:', err)
						}
					})
				},
				fail: () => {
					uni.showModal({
						title: '提示',
						content: '需要您授权保存图片到相册',
						confirmText: '去设置',
						success: (res : UniNamespace.ShowModalRes) => {
							if (res.confirm) {
								uni.openSetting()
							}
						}
					})
				}
			})
		}
		
		shareToTimeline() : void {
			uni.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline'],
				success: () => {
					uni.showToast({
						title: '请点击右上角分享',
						icon: 'none'
					})
				}
			})
		}
		
		onShareAppMessage() : ShareOptions {
			return {
				title: '另品网帮你来赚钱!',
				path: '/pages/index/index?inviteCode=' + this.inviteCode,
				imageUrl: this.qrCodeUrl,
				success(res : any) {
					uni.showToast({
						title: '分享成功',
						icon: 'success'
					})
				},
				fail(err : any) {
					uni.showToast({
						title: '分享失败',
						icon: 'none'
					})
				}
			}
		}
		
		onShareTimeline() : ShareOptions {
			return {
				title: '另品网帮你来赚钱!',
				path: '/pages/index/index?inviteCode=' + this.inviteCode,
				imageUrl: this.qrCodeUrl,
				success(res : any) {
					uni.showToast({
						title: '分享成功',
						icon: 'success'
					})
				},
				fail(err : any) {
					uni.showToast({
						title: '分享失败',
						icon: 'none'
					})
				}
			}
		}
	}